package com.yanqu.road.server.cmd.grandchild.exam;

import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.grandson.GrandChildModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GRAND_CHILD_JOIN_IMPERIAL_EXAM_FROM_CROSS, desc = "参加科举考试   跨服返回")
public class JoinImperialExamFromCrossCmd extends AbstractCommand {

    private String childId;
    private long examNo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GrandChildProto.CrossJoinExamRespMsg reqMsg = GrandChildProto.CrossJoinExamRespMsg.parseFrom(packet.getBytes());
        childId = reqMsg.getChildId();
        ret = reqMsg.getRet();
        examNo = reqMsg.getExamNo();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        player.getModule(GrandChildModule.class).joinExamFromCross(ret, childId, examNo);
    }

    @Override
    public void sendData(GamePlayer player) {
        GrandChildProto.JoinExamRespMsg.Builder builder = GrandChildProto.JoinExamRespMsg.newBuilder();
        builder.setRet(ret);
        player.sendPacket(ClientProtocol.U_GRAND_CHILD_JOIN_IMPERIAL_EXAM, builder);
    }
}
